import 'package:flutter/material.dart';
import 'package:get/get_navigation/src/routes/get_route.dart';
import 'package:library_base/route/i_router.dart';

///使用GetX进行路由管理
class Routers {

  ///主页面
  static const String main = "/main";

  ///启动页
  static const String splash = "/splashPage";

  ///登录页
  static const String login = "/login";

  ///工作台
  static const String workbench = "/workbench";

  ///工作台->创建采购单
  static const String createPurchaseOrderPage = "$workbench/CreatePurchaseOrderPage";

  ///工作台->创建采购单->选择供应商
  static const String chooseSupplierPage = "$createPurchaseOrderPage/ChooseSupplierPage";

  ///工作台->创建采购单->选择收货仓
  static const String chooseWarehousePage = "$createPurchaseOrderPage/ChooseWarehousePage";

  ///工作台->创建采购单->选择货主
  static const String chooseShipperPage = "$createPurchaseOrderPage/ChooseShipperPage";

  ///工作台->创建采购单->添加商品
  static const String addGoodsPage = "$createPurchaseOrderPage/AddGoodsPage";

  ///工作台->创建采购单->添加商品 Dialog
  static const String addGoodsInfoDialog = "$createPurchaseOrderPage/AddGoodsInfoDialog";

  // ///工作台->创建采购单->添加商品 Dialog
  // static const String addGoodsInfoDialog = "$createPurchaseOrderPage/AddGoodsInfoDialog";

  ///工作台->创建采购单->单头录入
  static const String singleHeadEntryPage = "$createPurchaseOrderPage/SingleHeadEntryPage";

  // --------------------------------------

  ///工作台->采购单任务
  static const String purchaseOrderTask = "$createPurchaseOrderPage/PurchaseOrderTask";

  ///工作台->采购单任务->采购员
  static const String chooseBuyerPage = "$createPurchaseOrderPage/ChooseBuyerPage";

  // --------------------------------------

  ///工作台->需求汇总
  static const String summaryListPage = "$createPurchaseOrderPage/SummaryListPage";

  ///工作台->需求汇总->变更采购员
  static const String chooseSummaryBuyerPage = "$createPurchaseOrderPage/ChooseSummaryBuyerPage";


  // --------------------------------------

  ///工作台->采购付款
  static const String purchasePaymentPage = "$createPurchaseOrderPage/PurchasePaymentPage";

  ///工作台->采购付款->采购付款详情
  static const String purchasePaymentDetailPage = "$purchasePaymentPage/PurchasePaymentDetailPage";

  // --------------------------------------

  ///调度
  static const String dispatcher = "/dispatcher";

  ///调度-选择车辆
  static const String carListPage = "$dispatcher/CarListPage";

  ///调度-选择司机
  static const String driverListPage = "$dispatcher/DriverListPage";

  ///调度-进行中-订单详情
  static const String progressDetailPage = "$dispatcher/ProgressDetailPage";

  // --------------------------------------

  ///Wms
  static const String wms = "/Wms";

  static const String deliverGoodsPage = "$wms/deliverGoodsPage";

  ///Wms - 入库订单
  static const String INCOMING_ORDERS = "$wms/INCOMING_ORDERS";

  ///Wms - 入库订单 - 详情
  static const String INCOMING_ORDERS_DETAIL_PAGE = "$INCOMING_ORDERS/INCOMING_ORDERS_DETAIL_PAGE";

  ///Wms - 入库订单 - 详情 - 单头录入
  static const String WMS_SINGLE_HEAD_ENTRY_PAGE = "$INCOMING_ORDERS_DETAIL_PAGE/WmsSingleHeadEntryPage";

  ///Wms - 入库订单 - 详情 - 单头录入 - 收货库位
  static const String LOCATION_PAGE = "$WMS_SINGLE_HEAD_ENTRY_PAGE/LocationPage";

  ///Wms - 订单打印
  static const String PRINT_DETAIL_PAGE = "$wms/PrintDetailPage";

  ///Wms - 蓝牙设备搜索
  static const String SEARCH_DEVICE_PAGE = "$PRINT_DETAIL_PAGE/SearchDevicePage";

  ///Wms - 蓝牙设备详情
  static const String DEVICE_DETAIL_PAGE = "$PRINT_DETAIL_PAGE/DeviceDetailPage";

  ///Wms-出库订单
  static const String OUTBOUND_ORDERS_MANAGE = "$dispatcher/OutboundOrdersManagePage";

  ///Wms-出库订单-详情
  static const String ORDER_DETAIL_PAGE = "$OUTBOUND_ORDERS_MANAGE/OrderDetailPage";

  ///Wms-出库订单-详情-库存商品分配(有条码)
  static const String INVENTORY_DISTRIBUTION_SINGLE_PAGE = "$ORDER_DETAIL_PAGE/InventoryDistributionSinglePage";

  ///Wms-出库订单-详情-库存商品分配(无条码)
  static const String INVENTORY_DISTRIBUTION_NO_SINGLE_PAGE = "$ORDER_DETAIL_PAGE/InventoryDistributionNoSinglePage";

  ///
  static const String SINGLE_HEAD_ENTRY_PAGE = "$ORDER_DETAIL_PAGE/SINGLE_HEAD_ENTRY_PAGE";

  ///设置
  static const String SET_UP_PAGE = "$main/SetUpPage";

  ///多语言
  static const String MULTILINGUAL_PAGE = "$SET_UP_PAGE/MultilingualPage";

  ///称重设置
  static const String settingWeighingPage = "$SET_UP_PAGE/SettingWeighingPage";


  // --------------------------------------

  ///错误页
  static const String page_404_not_found = "/not_found";

  ///路由表
  static final List<GetPage> getPages = [];

  static void init(List<IRouter> listRouter) {
    configureRoutes(listRouter);
  }

  ///路由配置
  static void configureRoutes(List<IRouter> listRouter) {
    for (var element in listRouter) {
      List<GetPage> pages = element.getPageBuilders();
      for (var page in pages) {
        getPages.add(page);
      }
    }
  }

  /// 返回
  static void goBack(BuildContext context) {
    unfocus();
    Navigator.pop(context);
  }

  /// 带参数返回
  static void goBackWithParams(BuildContext context, Object result) {
    unfocus();
    Navigator.pop<Object>(context, result);
  }

  static void unfocus() {
    // 使用下面的方式，会触发不必要的build。
    // FocusScope.of(context).unfocus();
    // https://github.com/flutter/flutter/issues/47128#issuecomment-627551073
    FocusManager.instance.primaryFocus?.unfocus();
  }
}
